import server from './request'

//封装登录接口
const login = data => {
    return server({url: '/login', method: 'POST', data})
}
// 左侧
const menus = () => {
    return server({url: '/menus', method: 'GET'})
}
//用户信息
const user = (params) => {
    return server({url: '/users', method: 'GET', params})
}
//更改
const usersuId = (uId, type) => {
    return server({url: `/users/${uId}/state/${type}`, method: 'PUT'})
}
//添加
const addUserAPI = (data) => {
    return server({url: '/users', method: 'POST', data})
}
//删除
const delUsers = (id) => {
    return server({url: `/users/${id}`, method: 'delete'})
}
const changeUser = (id, data) => {
    return server({url: `/users/${id}`, method: 'PUT', data})
}
//权限修改
const changeRoles = (id, data) => {
    console.log(id, data)
    return server({url: `/users/${id}/role`, method: 'PUT', data})
}
const roles = () => {
    return server({url: `/roles`, method: 'GET'})
}

//角色列表
const liaobiaoroles = () => {
    return server({url: `roles`, method: 'get',})
}
//角色列表信息
const liaobiaoxinxi = data => {
    return server({url: `roles`, method: 'post', data})
}
//角色列表删除
const liebiaoshanchu = (id) => {
    return server({url: `/roles/${id}`, method: 'delete'})
}
//角色列表编辑
const liebiaobianji = (id, data) => {
    return server({url: `/roles/${id}`, method: 'put', data})
}
const delroles = (roleId, rightId) => {
    return server({url: `roles/${roleId}/rights/${rightId}`, method: 'delete'})
}
//以树形权限列表形式显示
const getTree = () => {
    return server({url: `rights/tree`, method: 'get'})
}
const setRightsToRoleAPI = (roleId, data) => {
    return server({
        url: `roles/${roleId}/rights`,
        method: 'POST',
        data
    })
}

//权限列表
const tables = (type) => {
    return server({url: `/rights/${type}`, method: 'GET'})
}
//goods 商品列表
const goods = (params) => {
    return server({url: '/goods/', method: 'GET', params})
}
// 商品列表删除
const delgoods = (id) => {
    return server({url: `/goods/${id}`, method: 'delete'})
}
//商品分类
const categories = (params) => {
    return server({url: `/categories/`, method: 'GET', params})
}
//数据报表
const ShuJuBaoBiao = () => {
    return server({url: '/reports/type/1', method: 'GET'})
}
export {
    login, menus, user,
    usersuId, addUserAPI, delUsers,
    changeUser, roles, changeRoles,
    tables, liaobiaoroles, liaobiaoxinxi, liebiaoshanchu, liebiaobianji,
    goods, delgoods, categories, delroles, getTree,setRightsToRoleAPI,

    ShuJuBaoBiao
}

